package com.opgea.token.web.dto;

import java.math.BigInteger;

import com.opgea.token.domain.entities.TokenDetails;
import com.opgea.token.domain.interfaces.Marshallable;
import com.opgea.token.domain.qualifiers.TokenStatusQualifier;

public class TokenDetailsDTO implements Marshallable<TokenDetails> {

    private Long id;
    private Long companyId;
    private String tokenNo;
    private BigInteger mobileNo;
    private String emailId;
    private String name;
    private Long destinationId;
    private String destinationName;
    private Integer tokenStatus;
    private String metaData;
    private String appointmentDate;

    public TokenDetailsDTO() {
    }

    public TokenDetailsDTO(Long id, Long companyId, String tokenNo,
	    BigInteger mobileNo, String emailId, String name,
	    Long destinationId, String destinationName, Integer tokenStatus,
	    String appointmentDate) {
	this.id = id;
	this.companyId = companyId;
	this.tokenNo = tokenNo;
	this.mobileNo = mobileNo;
	this.emailId = emailId;
	this.name = name;
	this.destinationId = destinationId;
	this.destinationName = destinationName;
	this.tokenStatus = tokenStatus;
	this.appointmentDate = appointmentDate;
    }

    public Long getId() {
	return id;
    }

    public void setId(Long id) {
	this.id = id;
    }

    public Long getCompanyId() {
	return companyId;
    }

    public void setCompanyId(Long companyId) {
	this.companyId = companyId;
    }

    public String getTokenNo() {
	return tokenNo;
    }

    public void setTokenNo(String tokenNo) {
	this.tokenNo = tokenNo;
    }

    public String getEmailId() {
	return emailId;
    }

    public void setEmailId(String emailId) {
	this.emailId = emailId;
    }

    public BigInteger getMobileNo() {
	return mobileNo;
    }

    public void setMobileNo(BigInteger mobileNo) {
	this.mobileNo = mobileNo;
    }

    public String getName() {
	return name;
    }

    public void setName(String name) {
	this.name = name;
    }

    public Long getDestinationId() {
	return destinationId;
    }

    public void setDestinationId(Long destinationId) {
	this.destinationId = destinationId;
    }

    public String getDestinationName() {
	return destinationName;
    }

    public void setDestinationName(String destinationName) {
	this.destinationName = destinationName;
    }

    public Integer getTokenStatus() {
	return tokenStatus;
    }

    public void setTokenStatus(Integer tokenStatus) {
	this.tokenStatus = tokenStatus;
    }

    public String getMetaData() {
	StringBuilder metaBuilder = new StringBuilder();
	metaBuilder.append(this.name);
	metaBuilder.append(" ");
	metaBuilder.append(this.destinationName);
	metaBuilder.append(" ");
	metaBuilder.append(this.mobileNo);
	metaBuilder.append(" ");
	metaBuilder.append(this.tokenNo);
	metaBuilder.append(" ");
	metaBuilder.append(this.tokenStatus);
	metaBuilder.append(" ");
	metaBuilder.append(this.emailId);
	this.metaData = metaBuilder.toString();
	return metaData;
    }

    public void setMetaData(String metaData) {
	this.metaData = metaData;
    }

    public String getAppointmentDate() {
	return appointmentDate;
    }

    public void setAppointmentDate(String appointmentDate) {
	this.appointmentDate = appointmentDate;
    }

    @Override
    public void marshall(TokenDetails tokenDetails) {
	this.setTokenNo(tokenDetails.getId().toString());
	this.setName(tokenDetails.getName());

	if (tokenDetails.getId() != null) {
	    this.setId(tokenDetails.getId());
	}
	if (tokenDetails.getToken().getTokenNo() != null) {
	    this.setTokenNo(tokenDetails.getToken().getTokenNo().toString());
	}
	if (tokenDetails.getMobileNo() != null) {
	    this.setMobileNo(tokenDetails.getMobileNo());
	}
	if (tokenDetails.getEmailId() != null) {
	    this.setEmailId(tokenDetails.getEmailId());
	}
	if (tokenDetails.getDestination() != null) {
	    this.setDestinationId(tokenDetails.getDestination().getId());
	    this.setDestinationName(tokenDetails.getDestination().getName());
	}
	if (tokenDetails.getTokenStatus() != null) {
	    this.setTokenStatus(tokenDetails.getTokenStatus().ordinal());
	}

    }

    @Override
    public TokenDetails unmarshall(TokenDetails tokenDetails) {
	tokenDetails.setName(this.getName());
	tokenDetails.setMobileNo(this.getMobileNo());
	tokenDetails.setEmailId(this.getEmailId());
	// tokenDetails.setToken(token);
	// tokenDetails.setDestination(destination);
	tokenDetails.setTokenStatus(TokenStatusQualifier.NEW);
	tokenDetails.setMetaData(this.getMetaData());
	return tokenDetails;
    }

    @Override
    public String toString() {
	return "TokenDetailsDTO{" + "id=" + id + ", companyId=" + companyId
		+ ", tokenNo=" + tokenNo + ", mobileNo=" + mobileNo
		+ ", emailId=" + emailId + ", destinationId=" + destinationId
		+ ", destinationName=" + destinationName + ", tokenStatus="
		+ tokenStatus + ", metaData=" + metaData + ", appointmentDate="
		+ appointmentDate + '}';
    }
}
